<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "ErpEntryController.DataGrid"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData);
			$('#search_key').val() ? params.Filter = $('#search_key').val() : '';
			params.IsAcceptance = true;
			params.Auditing = 1;
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"bSortable": false, render:function(data, type, full, meta) {
				return '<a href="javascript:;" data-am-popover="{content: \''+ full.Suppliers.Name +'<br />联系人：'+ full.Suppliers.Contacts +'<br />电话：'+ full.Suppliers.Tel +'\', trigger: \'hover focus\'}">'+ full.Suppliers.Name +'</a>';
				
			}}
			,{"data" : "Number", "bSortable": false, render:function(data, type, full, meta) {
				return data;	
			}}
			,{"data" : "AcceptanceCheck", "bSortable": false}
			,{"bSortable": false,render:function(data, type, full, meta) {
				return full.CreatedBy + ' ' + timetransDate(full.CreatedAt);	
			}}
			,{"data" : "UpdatedAt", "bSortable": false, render:function(data, type, full, meta) {
				return full.UpdatedBy + ' ' + timetransDate(full.UpdatedAt);	
			}}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) { 
					btns = '';
                    btns += '&nbsp;<a class="am-btn am-btn-success am-btn-xs" href="/entry/accept_list/' + full.Id + '">验收</a>';

					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		,"drawCallback": function(settings){
			$('[data-am-popover]').popover();
		}   
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function delEntry(id) {
		layer.confirm('确定要删除所选记录吗？删除后不可恢复！', function(index){
			$.post('{{ urlfor "ErpEntryController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
	
	function dialogReback() {
		tables.ajax.reload();
	}
	
	$('#insert-entry').click(function(){
		var url = '{{urlfor "ErpEntryController.SelectSuppliers"}}';
		
		layer.open({
            type: 2,
            title: '选对供应商',
            shadeClose: false,
            shade: 0.2,
            maxmin: true,
            shift: 1,
            area: ['410px', '468px'],
            content: url
        });
		
		return false;	
	});
	
	function SelectSuppliersRollBack(id) {
		layer.closeAll();
		location = '{{ urlfor "ErpEntryController.Edit" }}/'+id;	
	}
</script>